﻿@using XStudio.WebFramework.Mvc.Extensions
<script type="text/javascript">

    var List = {};
    List.DelUrl = "";
    List.EditUrl = "";


    List.NameEditFormatter = function (value, rec, index) {
        var html = "";
        if (rec.SexCodeID == 1)
            html += "<img title='男' src='" + $("#maleUrl").val() + "' align='absmiddle' style='border-width:0px;'>";
        else if (rec.SexCodeID == 2)
            html += "<img title='女' src='" + $("#femaleUrl").val() + "' align='absmiddle' style='border-width:0px;'>";

        html += "<a  href='" + $("#editUrl").val() + "/" + rec.UID + "' onclick='List.Edit(this); return false;' >" + value + "</a>";
        return html;
    }
    List.NameFormatter = function (value, rec, index) {
        var html = "";
        if (rec.SexCodeID == 1)
            html += "<img title='男' src='" + $("#maleUrl").val() + "' align='absmiddle' style='border-width:0px;'>";
        else if (rec.SexCodeID == 2)
            html += "<img title='女' src='" + $("#femaleUrl").val() + "' align='absmiddle' style='border-width:0px;'>";

        html += value;
        return html;
    }

    List.DeleteFormatter = function (value, rec, index) {
        if (rec.StateID == 1)
            return "";
        return "<a  class='btn-del' href='" + List.DelUrl + "/" + rec.UID + "' onclick='List.Delete(this); return false;' >删除</a>";
    }

    List.EditFormatter = function (value, rec, index) {
        return "<a  class='btn-edit' href='" + $("#editUrl").val() + "/" + rec.UID + "' onclick='List.Edit(this); return false;' >修改</a>";
    }
    List.ResetInstitutionFormatter = function (value, rec, index) {
        return "<a  class='btn-userins' href='" + $("#resetInstitutionUrl").val() + "/" + rec.UID + "' onclick='List.ResetInstitution(this); return false;' >转部门</a>";
    }
    List.ResetFormatter = function (value, rec, index) {
        return "<a  class='btn-lock' href='" + $("#resetUrl").val() + "/" + rec.UID + "' onclick='List.Reset(this); return false;' >重置密码</a>";
    }
    List.AuthorizeFormatter = function (value, rec, index) {
        return "<a  class='btn-manage' href='" + $("#setAuthorizeUrl").val() + "/" + rec.UID + "' onclick='List.SetAuthorize(this); return false;' >设置权限</a>";
    }

    List.InstitutionNamePathFormatter = function (value, rec, index) {
        if (rec.InstitutionID == 0) return rec.InstitutionDirectoryShortName;
        return rec.InstitutionDirectoryShortName + '/' + rec.InstitutionNamePath;
    }
    List.StateFormatter = function (value, rec, index) {
        return value == 1 ? "启用" : "禁用";
    }
    
    List.Delete = function (e) {
        if (!confirm("确认要删除吗？"))
            return;
        $.post($(e).attr("href"), function (data) {
            if (data.IsOK) {
                $('#tbList').datagrid('reload');
            }
            else
                alert(data.Description);
        });
    }
    List.Edit = function (e) {
        if ($('#tabsMain').tabs('exists', "修改管理员信息")) {
            $('#tabsMain').tabs('close', "修改管理员信息");
        }
        Common.ShowTab(e, "修改管理员信息");
    }

    List.SetAuthorize = function (e) {
        $.createWin({ url: e.href, width: 600, height: 550, title: '设置管理员权限' });
    }

    List.Reset = function (e) {
        $.createWin({ url: e.href, width: 500, height: 350, title: '重置密码' });
    }
    List.ResetInstitution = function (e) {
        $.createWin({ url: e.href, width: 500, height: 230, title: '转部门' });
    }

    List.DeleteSelected = function (e) {
        var selected = $("#tbList").datagrid("getSelections");
        if (selected.length == 0) {
            alert("请选择要删除的管理员。");
            return;
        }

        var idString = "";
        $.each(selected, function (index, item) {
            idString += item.UID + ",";
        });



        if (!confirm("确认要删除选中管理员吗？"))
            return;
        $.post($(e).attr("href"), { id: idString }, function (data) {
            if (data.IsOK) {
                $('#tbList').datagrid('reload');
            }
            else
                alert(data.Description);
        });
    }

    List.ResetSelected = function (e) {
        var selected = $("#tbList").datagrid("getSelections");
        var idString = "";
        $.each(selected, function (index, item) {
            idString += item.UID + ",";
        });
        if (selected.length == 0) {
            alert("请选择要重置密码的管理员。");
            return;
        }

        $.createWin({ url: e.href + "?id=" + idString, width: 500, height: 350, title: '重置密码' });
    }

    List.ResetInstitutionSelected = function (e) {
        var selected = $("#tbList").datagrid("getSelections");
        var idString = "";
        $.each(selected, function (index, item) {
            idString += item.UID + ",";
        });
        if (selected.length == 0) {
            alert("请选择要转移区域的管理员。");
            return;
        }

        $.createWin({ url: e.href + "?id=" + idString, width: 500, height: 350, title: '转部门' });
    }

    List.SetAuthorizeSelected = function (e) {
        var selected = $("#tbList").datagrid("getSelections");
        var idString = "";
        $.each(selected, function (index, item) {
            idString += item.UID + ",";
        });
        if (selected.length == 0) {
            alert("请选择要设置权限的管理员。");
            return;
        }
        $.createWin({ url: e.href + "?id=" + idString, width: 600, height: 550, title: '设置选中管理员权限' });
    }

    List.IsLoaded = false;

    $(document).ready(function () {
        if (List.IsLoaded) return;
        List.IsLoaded = true;

        List.DelUrl = $("#delUrl").val();
        List.EditlUrl = $("#editUrl").val();

        $('#tbList').datagrid({ pagination: true });
        //$('#tbList').datagrid({ pagination: true, onLoadSuccess: Common.DataGridLoad });
    });
</script>
@Html.Hidden("maleUrl", Url.Content("~/Content/icon/male.gif"))
@Html.Hidden("femaleUrl", Url.Content("~/Content/icon/Female.gif"))
@Html.Hidden("resetUrl", Url.Action("ResetPassword"))
@Html.Hidden("delUrl", Url.Action("Delete"))
@Html.Hidden("editUrl", Url.Action("Edit"))
@Html.Hidden("setAuthorizeUrl", Url.Action("SetAuthorize", "Authorize"))
@Html.Hidden("resetInstitutionUrl", Url.Action("ResetInstitution"))
<div class="tt-attach">
    <ul class="op">
        @Html.WebPartButton("删除选中", "Delete", null, new { onclick = "List.DeleteSelected(this); return false;", @class = "btn-del" })
        @Html.WebPartButton("管理员密码", "ResetPassword", null, new { onclick = "List.ResetSelected(this); return false;", @class = "btn-lock" })
        @Html.WebPartButton("更改区域", "ResetInstitution", null, new { onclick = "List.ResetInstitutionSelected(this); return false;", @class = "btn-userins" })
        @Html.WebPartButton("管理员权限", "SetAuthorize", "Authorize", null, new { onclick = "List.SetAuthorizeSelected(this); return false;", @class = "btn-manage" })
    </ul>
</div>
<div style="padding: 5px 10px;">
    <table id="tbList" striped="true"  rownumbers="true" fix="true"  fitColumns="true" title=""
     idfield="UID" checkbox="true" url="@Url.Action("ListData")">
        <thead>
            <tr>
                <th field="UID" checkbox="true" width="150">
                </th>
                @if (Html.Auth("Edit"))
                {
                    <th field="EmployeeName" formatter="List.NameEditFormatter" width="130">
                        用户姓名
                    </th>
                }
                else
                {
                    <th field="EmployeeName" formatter="List.NameFormatter" width="130">
                        用户姓名
                    </th>
                }
                <th field="Account" width="150">
                    用户账号
                </th>
                <th field="InstitutionNamePath" formatter="List.InstitutionNamePathFormatter"  width="400">
                    所属区域
                </th>
                <td field="MobilePhone" width="100">
                联系电话
                </td>
                <th field="StateCodeID" formatter="List.StateFormatter" width="50" align="center">
                    状态
                </th>
                @if (Html.Auth("SetAuthorize", "Authorize"))
                {
                    <th field="权限" width="50" formatter="List.AuthorizeFormatter" align="center">
                        设置权限
                    </th>
                }
                @if (Html.Auth("ResetPassword"))
                {
                    <th field="重置密码" width="60" formatter="List.ResetFormatter" align="center">
                        重置密码
                    </th>
                }
                @if (Html.Auth("Edit"))
                {
                    <th field="修改" width="50" formatter="List.EditFormatter" align="center">
                        修改
                    </th>
                }
                @if (Html.Auth("Delete"))
                {
                    <th field="删除" width="50" formatter="List.DeleteFormatter" align="center">
                        删除
                    </th>
                }
            </tr>
        </thead>
    </table>
</div>
